package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/7 15:39
 * @description
 */
public class Code868 {
    public static void main(String[] args) {
        new Code868().binaryGap(5);
    }

    public int binaryGap(int N) {
        String s = Integer.toBinaryString(N);
        if (s.indexOf("1") == s.lastIndexOf("1")) {
            return 0;
        }
        //分割后最后一位为1则数组最后少一位，所以补个0
        s += 0;
        int result = 1;
        String[] split = s.split("1");
        for (int i = 1; i < split.length - 1; i++) {
            if (split[i].length() > result) {result = split[i].length();}
        }
        return result;
    }
}
